import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(),
  Components({
    resolvers: [VantResolver()],
  }),
  ],

  base: '/h5/',
  css: {
    preprocessorOptions: {
      scss: {
        charset: false
      }
    }
  },
  // 添加这个配置来完全禁用 ESBuild
  // 修改为部分配置，而不是完全禁用
  esbuild: {
    target: 'es2020',
    // 只禁用可能导致冲突的功能
    minify: false,
    legalComments: 'none',
    // 保持对 TypeScript 的支持
    tsconfigRaw: {
      compilerOptions: {
        // 确保 TypeScript 支持
        experimentalDecorators: true,
        useDefineForClassFields: false
      }
    }
  },
  build: {
    // 完全禁用所有压缩和优化
    minify: false,
    sourcemap: false,
    cssMinify: false,
    target: 'esnext',
    // 配置 Rollup 选项
    rollupOptions: {
      output: {
        // 禁用所有优化
        hoistTransitiveImports: false,
        manualChunks: undefined,
        preserveModules: false
      },
      treeshake: false
    }
  },
  // 禁用所有优化
  // optimizeDeps: {
  //   disabled: true
  // },
  resolve: {
    // 设置路径别名
    alias: {
      "@": resolve(__dirname, "./src"),
      "*": resolve(""),
    },
  },

  server: {
    port: 8080,
    // host: true,
    host: "0.0.0.0",
    proxy: {
      //测试地址
      '/doctor-cheese-anatomy': {
        target: 'https://it.zmylclould.com:19000/doctor-cheese-anatomy',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/doctor-cheese-anatomy/, ''),
      },
      //测试地址
      "/megagame-platform": {
        target: "https://it.zmylclould.com:19000/megagame-platform",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/megagame-platform/, ""),
      },
      '/doctor-cheese': {
        target: 'https://www.zhishiyisheng.com/doctor-cheese',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/doctor-cheese/, ''),
      },
      '/bpt': {
        target: 'https://it.zmylclould.com:18089/bpt',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/bpt/, ''),
      },
      '/zmc': {
        target: 'https://it.zmylclould.com:18089/zmc',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/zmc/, ''),
      },
      '/upload-server': {
        target: 'https://it.zmylclould.com:18089/upload-server',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/upload-server/, ''),
      },
      '/zhongmaoyunService': {
        target: 'https://it.zmylclould.com:18089/zhongmaoyunService',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/zhongmaoyunService/, ''),
      },
      '/o8slide-viewer': {
        target: 'https://it.zmylclould.com:19000/o8slide-viewer',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/o8slide-viewer/, ''),
      },
      '/slide-viewer': {
        target: 'https://it.zmylclould.com:19000/slide-viewer',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/slide-viewer/, ''),
      },
      '/png-viewer': {
        target: 'https://it.zmylclould.com:19000/png-viewer',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/png-viewer/, ''),
      },
    }
  },
})